/**
 * Created by Administrator on 2014/8/20.
 */
var Handler = require('./../Handler');
var util = require('util');
var o2x = require('object-to-xml');
var xmlSimplify = require('../../tools/xmlSimplify');
var wxCrypto = require('../../tools/wxCrypto');


wxHandler.prototype.wxXmlRequest = function(){
    var originalXml = this.req.body.xml;
    if(originalXml){
        var simplifyXml =  xmlSimplify(originalXml);
        return simplifyXml;
    }else{
        return '';
    }
};

wxHandler.prototype.wxXmlResponse = function(res,ob){
    res.set('Content-Type', 'text/xml');
    var xmlRes = o2x({xml:ob});
    res.send(xmlRes);
}


/*
 * 用于微信校验url地址，认证是来着微信的请求后，返回随机字符串即可
 * */
validateToken =function(req,res) {
    var query = req.query;
    if (query.signature == wxCrypto(query)) {
        res.send(req.query.echostr);
    }
    else {
        res.send("Bad Token!");
    }
}



